package com.wskh.vod.controller;


import com.wskh.commonUtil.R;
import com.wskh.vod.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path;
import java.io.IOException;

@Api(value = "阿里云视频点播微服务")
@RestController("/eduVod/video")
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE}) // 允许请求跨域
public class VodController {
    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "视频上传")
    @PostMapping("upload")
    public R uploadVideo(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) throws Exception {
        System.out.println(111);
        String videoId = videoService.uploadVideo(file);
        return R.ok().message("视频上传成功").data("videoId", videoId);
    }

    @ApiOperation(value = "根据视频id删除云端视频")
    @PostMapping("deleteVideoById/{id}")
    public R deleteVideoById(@PathVariable(name = "id") String id){
        boolean b = videoService.deleteVideoById(id);
        if(b){
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }

    @PostMapping("vod/{id}")
    public R testVod(@PathVariable String id) throws IOException {
        //返回r对象
        return R.ok().message("id = "+id);
    }

}
